package it.uniroma2.sd.db;

import java.io.Serializable;
import java.util.Vector;

public interface ITable extends Serializable
{
    /**
     * Retrieve the table name.
     * 
     * @return The name of the table.
     */
    public String getName();

    /* insert and update */
    /**
     * Put or update one column in the row identified by rowkey in this table.
     * 
     * @param rowkey The key corresponding to the row to be modified.
     * @param column The new column to use for put or update.
     */
    public void put(String rowkey, IColumn column);

    // public void put(String rowkey, String columnkey, Object columnvalue); // FIXME necessaria? vincola alla creazione di un tipo di column al suo interno

    /**
     * Put or update columns in the row identified by rowkey.
     * <p>
     * It is also possible to pass directly an array of IColumn.
     * </p>
     * 
     * @param rowkey The key corresponding to the row to be modified.
     * @param columns The variable arguments list of columns to use for put or update.
     */
    public void put(String rowkey, IColumn... columns);

    /* get */
    /**
     * Retrieve the IColumn from the specified row using the specified columnkey.
     * 
     * @param rowkey The row from which retrieve the column.
     * @param columnkey The key of the column to get.
     * @return The IColumn found or null if it does not exists in this the IColumnsGroup or the IColumnsGroup itself does not exist because the specified row is not present in this table.
     */
    public IColumn getColumn(String rowkey, String columnkey);

    /**
     * Get the whole row (that is get all the columns).
     * 
     * @param rowkey The key of the row containing the columns.
     * @return A Vector containing the columns in the specified row or null if the row is not present in this table.
     */
    public Vector<IColumn> getAllColumns(String rowkey);

    /* delete */
    /**
     * Delete a single column using its key from the specified row.
     * 
     * @param rowkey The key of the row from which delete the column.
     * @param columnkey The key of the column to delete.
     * @return True if the deletion succeed, false otherwise.
     */
    public boolean deleteColumn(String rowkey, String columnkey);

    /**
     * Delete a variable number of columns using their key from the specified row.
     * <p>
     * If it is necessary to delete all the columns in a row use {@link #deleteRow(String)}, because it needs less effort.
     * </p>
     * 
     * @param rowkey The key of the row from which delete the column.
     * @param columnkey The key of the column to delete.
     * @return If, after deletion, IColumnsGroup is not empty, return a positive number or zero indicating the number of non existing columns in the delete request. If, after deletion, IColumnsGroup is empty, return -(the_number_of_non_existing_column_in_the_delete_request) -2. If the row is not present in this table return -1;
     */
    public int deleteColumns(String rowkey, String... columnkey); // FIXME necessaria??? return un pò complicato...

    /**
     * Delete a complete row from the table.
     * 
     * @param rowkey The key of the row to delete.
     * @return True if the deletion succeed, false otherwise.
     */
    public boolean deleteRow(String rowkey);

    // private void createRowWithColumn(String rowkey, Column column)
}
